home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / thefuelguage.e < prev    next >
Text File  |  1992-09-02  |  20KB  |  688 lines

  1. /*
  2. TABS=4 · Please try to keep the source with the executable.
  3.  
  4.  
  5.                               The Fuel Guage
  6.  
  7.                    © COPYRIGHT 1994 Christian Catchpole
  8.  
  9.                             COLD COFFEE DESIGN
  10.                    MADE IN AUSTRALIA - CONTAINS CAFFEINE
  11.  
  12.  Snail Mail: CHRISTIAN CATCHPOLE, P.O. BOX 388, CHERMSIDE 4032, AUSTRALIA
  13.  
  14.                              *** IMPORTANT ***
  15.  
  16. DISCLAIMER:   I  DO  NOT  CLAIM THAT THIS PROGRAM IS FIT FOR ANY PARTICULAR
  17. PURPOSE AND THUS I CAN NOT BE HELD RESPONSIBLE FOR ANY DAMAGE CAUSED BY THE
  18. USE OR MISUSE OF THIS PROGRAM.  USE THIS AT YOUR OWN RISK.
  19.  
  20. ...other than that, enjoy yourself!
  21.  
  22. Q.  What is "The Fuel Guage"?
  23.  
  24. A.   A  little  program written in E by yours truely that opens a window on
  25. the  defualt  public screen and not only displays a guage of available CHIP
  26. and FAST memory, but throws a few vector images around to entertain you.
  27.  
  28. This program runs at priority -1 for your convenience.
  29.  
  30. I  gave  this to Wouter to release on the condition that he doesn't mind me
  31. using  his  vector  routines (those from vec.e).  So, if your reading this,
  32. it's  obvious  he  was  cool about it.  I've written a more appropriate one
  33. myself but it would take too long to implement - in this version anyway.
  34.  
  35. I won't ask for any donation or such for using this since it is pritty weak
  36. and  the vector code isn't mine to sell!  Although, nice letters, postcards
  37. and  briefcases full of unmarked bills would be appreciated.  :-) What I do
  38. ask  is  that  you  use and support the use of Amiga E.  Nothing else comes
  39. close.   (when will Wouter think of a catchy slogan - he's already asked me
  40. to appear in his prime time TV commercials :)
  41.  
  42. Wander  through  the source and see what you think.  I don't not claim that
  43. this  is  written  to it's best efficiency - infact i know of several areas
  44. that  are  just  plain  crap  (LONG shape Lists for example).  I have tried
  45. though  to  show  good programming practices - perform() for example, shows
  46. how  you  can use global vars and quoted expressions to your advantage when
  47. multiple  processing  objects  (even  though  the  memlist  only contains 2
  48. objects!  :-)
  49.  
  50. Oh  yair.   E users and all others please write (100% Legal :).  I would be
  51. especialy interested in you if you...
  52.  
  53.     · Live far way away into the distance. (AND speak english!)
  54.     · Have an interest in writing really tricky yet system friendly code.
  55.     · Appreciate the importance of a good cup of coffee.
  56.     · Are NOT under the influence of drugs.
  57.     · Are NOT under the influence of XCopy (100% Legal :).
  58.     · Sleep with one eye open so that if your Amiga gets up in the middle
  59.       of the night to conqure the world, you want to see it (and then read
  60.       the source code to see how it's done!)
  61.     · Enjoy writing pages and pages of miscelaneousness.
  62.  
  63. Enjoy.
  64.  
  65. Christian.
  66. Tue Jun 14 14:48:19 1994
  67.  
  68. */
  69.  
  70. MODULE    'intuition/intuition',
  71.         'gadtools','libraries/gadtools',
  72.         'exec/memory',
  73.         'graphics/displayinfo','graphics/text','graphics/rastport',
  74.         'graphics/gfx',
  75.         'diskfont','libraries/diskfont'
  76.  
  77. OBJECT form_gadget
  78.     kind        :INT
  79.     x            :INT
  80.     y            :INT
  81.     dx            :INT
  82.     dy            :INT
  83.     text        :LONG
  84.     func        :LONG
  85. ENDOBJECT
  86.  
  87. OBJECT form_bevel
  88.     x            :INT
  89.     y            :INT
  90.     dx            :INT
  91.     dy            :INT
  92.     rec            :INT
  93.     col            :INT
  94. ENDOBJECT
  95.  
  96. OBJECT memblock
  97.     type        :LONG
  98.     text        :LONG
  99.     position    :INT
  100.     total        :LONG
  101.     avail        :LONG
  102.     lastavail    :LONG
  103. ENDOBJECT
  104.  
  105. CONST    VERSION=37,        /* Minimum V2.0 (of course) */
  106.         WIN_FLAGS    =    WFLG_CLOSEGADGET OR WFLG_DRAGBAR OR WFLG_DEPTHGADGET OR WFLG_NOCAREREFRESH OR WFLG_ACTIVATE,
  107.         WIN_IDCMP    =    IDCMP_CLOSEWINDOW OR IDCMP_REFRESHWINDOW OR IDCMP_GADGETUP OR IDCMP_ACTIVEWINDOW,
  108.  
  109.         LEFT = 14,
  110.         RIGHT = 244,
  111.         CENTRE = 150,
  112.  
  113.         TOP1 = 24,
  114.         TOP2 = 33,
  115.         BOTTOM1 = 152,
  116.         BOTTOM2 = 161,
  117.  
  118.         GRY=0,BLK=1,WHT=2,BLU=3,    /* WB 2.0 colours */
  119.  
  120.         RECESSED = 2,
  121.  
  122.         SLOW=10,
  123.         FAST=2,
  124.  
  125.         R=120,
  126.         MAXCOUNT=50        /* # of times to draw shap before changing it */
  127.  
  128. ENUM    NOERROR=NIL,
  129.         NOMEM,
  130.         NOLIBRARY,
  131.         NOKICK,
  132.         NOLOCK,
  133.         NOVISUAL,
  134.         NOWINDOW,
  135.         NOGADGETS
  136.  
  137. RAISE    NOMEM        IF New()=NIL,
  138.         NOLIBRARY    IF OpenLibrary()=NIL,
  139.         NOKICK        IF KickVersion()=NIL,
  140.         NOLOCK        IF LockPubScreen()=NIL,
  141.         NOVISUAL    IF GetVisualInfoA()=NIL,
  142.         NOWINDOW    IF OpenWindow()=NIL,
  143.         NOGADGETS    IF CreateGadgetA()=NIL,
  144.         NOGADGETS    IF CreateContext()=NIL
  145.  
  146. DEF    wnd            :PTR TO window,
  147.     rast        :PTR TO rastport,
  148.     scr, visual, context, lastgad,
  149.     thistask, origpri,
  150.  
  151.     gad            :PTR TO form_gadget,
  152.     bev            :PTR TO form_bevel,
  153.  
  154.     sintab        :PTR TO INT,
  155.  
  156.     imes        :PTR TO intuimessage,
  157.     iaddress    :PTR TO gadget,
  158.     imclass, code,
  159.  
  160.     mem            :PTR TO memblock,
  161.     memlist        :PTR TO LONG,
  162.  
  163.     messagelist    :PTR TO LONG,
  164.  
  165.     phi=NIL,
  166.     theta=NIL,
  167.  
  168.     images=TRUE,
  169.     speed=FAST,
  170.  
  171.     frameloop,
  172.     shapelist    :PTR TO LONG,
  173.     shapenames    :PTR TO LONG,
  174.     shapesizes    :PTR TO LONG,
  175.     currentshape=NIL, count,
  176.  
  177.     scrolldown=NIL,
  178.  
  179.     gstr[40]    :STRING,                /* a general purpose string */
  180.     x,y
  181.  
  182. PROC main() HANDLE
  183.     /* typing 'thefuelguage ?' from a shell will print the about text. */
  184.     IF Char(arg)="?"
  185.         WriteF('\n\s\n',{txt_about})
  186.         RETURN
  187.     ENDIF
  188.     KickVersion(VERSION)
  189.  
  190.     /* I didn't like Wouter's sintab(PC) - not very E at all! */
  191.  
  192.     sintab:=[    $0000,$0004,$0008,$000D,$0011,$0016,$001A,$001F,
  193.                 $0023,$0027,$002C,$0030,$0035,$0039,$003D,$0041,
  194.                 $0046,$004A,$004E,$0053,$0057,$005B,$005F,$0063,
  195.                 $0067,$006B,$006F,$0073,$0077,$007B,$007F,$0083,
  196.                 $0087,$008A,$008E,$0092,$0095,$0099,$009C,$00A0,
  197.                 $00A3,$00A7,$00AA,$00AD,$00B1,$00B4,$00B7,$00BA,
  198.                 $00BD,$00C0,$00C3,$00C6,$00C8,$00CB,$00CE,$00D0,
  199.                 $00D3,$00D5,$00D8,$00DA,$00DC,$00DF,$00E1,$00E3,
  200.                 $00E5,$00E7,$00E8,$00EA,$00EC,$00EE,$00EF,$00F1,
  201.                 $00F2,$00F3,$00F5,$00F6,$00F7,$00F8,$00F9,$00FA,
  202.                 $00FB,$00FB,$00FC,$00FD,$00FD,$00FE,$00FE,$00FE,
  203.                 $00FE,$00FE,$00FF,$00FE,$00FE,$00FE,$00FE,$00FE,
  204.                 $00FD,$00FD,$00FC,$00FB,$00FB,$00FA,$00F9,$00F8,
  205.                 $00F7,$00F6,$00F5,$00F3,$00F2,$00F1,$00EF,$00EE,
  206.                 $00EC,$00EA,$00E8,$00E7,$00E5,$00E3,$00E1,$00DF,
  207.                 $00DC,$00DA,$00D8,$00D5,$00D3,$00D0,$00CE,$00CB,
  208.                 $00C8,$00C6,$00C3,$00C0,$00BD,$00BA,$00B7,$00B4,
  209.                 $00B1,$00AD,$00AA,$00A7,$00A3,$00A0,$009C,$0099,
  210.                 $0095,$0092,$008E,$008A,$0087,$0083,$007F,$007B,
  211.                 $0077,$0073,$006F,$006B,$0067,$0063,$005F,$005B,
  212.                 $0057,$0053,$004E,$004A,$0046,$0041,$003D,$0039,
  213.                 $0035,$0030,$002C,$0027,$0023,$001F,$001A,$0016,
  214.                 $0011,$000D,$0008,$0004,$0000,$FFFC,$FFF8,$FFF3,
  215.                 $FFEF,$FFEA,$FFE6,$FFE1,$FFDD,$FFD9,$FFD4,$FFD0,
  216.                 $FFCB,$FFC7,$FFC3,$FFBF,$FFBA,$FFB6,$FFB2,$FFAD,
  217.                 $FFA9,$FFA5,$FFA1,$FF9D,$FF99,$FF95,$FF91,$FF8D,
  218.                 $FF89,$FF85,$FF81,$FF7D,$FF79,$FF76,$FF72,$FF6E,
  219.                 $FF6B,$FF67,$FF64,$FF60,$FF5D,$FF59,$FF56,$FF53,
  220.                 $FF4F,$FF4C,$FF49,$FF46,$FF43,$FF40,$FF3D,$FF3A,
  221.                 $FF38,$FF35,$FF32,$FF30,$FF2D,$FF2B,$FF28,$FF26,
  222.                 $FF24,$FF21,$FF1F,$FF1D,$FF1B,$FF19,$FF18,$FF16,
  223.                 $FF14,$FF12,$FF11,$FF0F,$FF0E,$FF0D,$FF0B,$FF0A,
  224.                 $FF09,$FF08,$FF07,$FF06,$FF05,$FF05,$FF04,$FF03,
  225.                 $FF03,$FF02,$FF02,$FF02,$FF02,$FF02,$FF01,$FF02,
  226.                 $FF02,$FF02,$FF02,$FF02,$FF03,$FF03,$FF04,$FF05,
  227.                 $FF05,$FF06,$FF07,$FF08,$FF09,$FF0A,$FF0B,$FF0D,
  228.                 $FF0E,$FF0F,$FF11,$FF12,$FF14,$FF16,$FF18,$FF19,
  229.                 $FF1B,$FF1D,$FF1F,$FF21,$FF24,$FF26,$FF28,$FF2B,
  230.                 $FF2D,$FF30,$FF32,$FF35,$FF38,$FF3A,$FF3D,$FF40,
  231.                 $FF43,$FF46,$FF49,$FF4C,$FF4F,$FF53,$FF56,$FF59,
  232.                 $FF5D,$FF60,$FF64,$FF67,$FF6B,$FF6E,$FF72,$FF76,
  233.                 $FF79,$FF7D,$FF81,$FF85,$FF89,$FF8D,$FF91,$FF95,
  234.                 $FF99,$FF9D,$FFA1,$FFA5,$FFA9,$FFAD,$FFB2,$FFB6,
  235.                 $FFBA,$FFBE,$FFC3,$FFC7,$FFCB,$FFD0,$FFD4,$FFD9,
  236.                 $FFDD,$FFE1,$FFE6,$FFEA,$FFEF,$FFF3,$FFF8,$FFFC,
  237.                 $0000,$0004,$0008,$000D,$0011,$0016,$001A,$001F,
  238.                 $0023,$0027,$002C,$0030,$0035,$0039,$003D,$0041,
  239.                 $0046,$004A,$004E,$0053,$0057,$005B,$005F,$0063,
  240.                 $0067,$006B,$006F,$0073,$0077,$007B,$007F,$0083,
  241.                 $0087,$008A,$008E,$0092,$0095,$0099,$009C,$00A0,
  242.                 $00A3,$00A7,$00AA,$00AD,$00B1,$00B4,$00B7,$00BA,
  243.                 $00BD,$00C0,$00C3,$00C6,$00C8,$00CB,$00CE,$00D0,
  244.                 $00D3,$00D5,$00D8,$00DA,$00DC,$00DF,$00E1,$00E3,
  245.                 $00E5,$00E7,$00E8,$00EA,$00EC,$00EE,$00EF,$00F1,
  246.                 $00F2,$00F3,$00F5,$00F6,$00F7,$00F8,$00F9,$00FA,
  247.                 $00FB,$00FB,$00FC,$00FD,$00FD,$00FE,$00FE,$00FE,
  248.                 $00FE,$00FE,$00FF,$00FE,$00FE,$00FE,$00FE,$00FE    ]:INT
  249.  
  250.     /* Set the Rnd() seed with the current time */
  251.     CurrentTime({x},{y})
  252.     Rnd(-x)
  253.  
  254.     thistask:=FindTask(NIL)
  255.     gadtoolsbase:=OpenLibrary({txt_gadtools},VERSION)
  256.     CreateContext({context})
  257.     lastgad:=context
  258.     scr:=LockPubScreen(NIL)
  259.     visual:=GetVisualInfoA(scr,NIL)
  260.  
  261.     /* make our gadgets (all 2 of them! :) */
  262.  
  263.     ForAll({gad},
  264.         [    [BUTTON_KIND,5,167,290,12,'About and Options',`options()]:form_gadget,
  265.             [BUTTON_KIND,5,180,290,12,'Jump Around The Place',`jumpabout()]:form_gadget    ],
  266.         `lastgad:=CreateGadgetA(gad.kind,lastgad,
  267.             [    gad.x,gad.y,gad.dx,gad.dy,gad.text,
  268.                 ['topaz.font',8,0,0]:textattr,
  269.                 2,0,visual,gad.func    ]:newgadget,NIL) )
  270.  
  271.     /* open our window.. */
  272.  
  273.     wnd:=OpenWindowTagList(NIL,
  274.     [    WA_FLAGS,WIN_FLAGS,WA_IDCMP,WIN_IDCMP,
  275.         WA_LEFT,100,    WA_TOP,40,
  276.         WA_WIDTH,300,    WA_HEIGHT,195,
  277.         WA_TITLE,'The Fuel Guage',
  278.         WA_GADGETS,context,NIL,NIL    ])
  279.  
  280.     UnlockPubScreen(NIL,scr)
  281.     scr:=NIL
  282.     rast:=stdrast:=wnd.rport
  283.     SetTopaz(8)
  284.  
  285.     /* fill the screen with BLU */
  286.  
  287.     SetAPen(rast,BLU)
  288.     RectFill(rast,wnd.borderleft,wnd.bordertop,
  289.         wnd.width-wnd.borderright-1,wnd.height-wnd.borderbottom-1)
  290.  
  291.     ForAll({bev},
  292.         [    [5,15,290,150,RECESSED,GRY]:form_bevel,
  293.             [65,38,170,105,NIL,BLK]:form_bevel,
  294.             [10,38,50,105,NIL,GRY]:form_bevel,
  295.             [240,38,50,105,NIL,GRY]:form_bevel    ],
  296.         `Box(bev.x,bev.y,bev.x+bev.dx-1,bev.y+bev.dy-1,
  297.             bev.col) BUT DrawBevelBoxA(rast,bev.x,bev.y,bev.dx,bev.dy,
  298.             [    GT_VISUALINFO,visual,
  299.                 IF bev.rec THEN GTBB_RECESSED ELSE NIL,NIL,NIL]))
  300.  
  301.     RefreshGadgets(context,wnd,NIL)
  302.     Gt_RefreshWindow(wnd,NIL)
  303.  
  304.     messagelist:=    [    'Amiga E 2.1b','Yo!','COLD COFFEE DESIGN',
  305.                         'CONTAINS CAFFEINE','MADE IN AUSTRALIA',
  306.                         'The earth is flat.','Elvis is dead',
  307.                         'Morrissey is good','Needle Nardle Noo',
  308.                         'Yacabarcoo','Awooble','Caffine','Coffee',
  309.                         'Tea','Coke (tm)','Pizza','Supreem',
  310.                         'Ham and Pineapple','Alcohol','Hmmm.. Beer',
  311.                         'Southern Comfort','Confection','Chocolate',
  312.                         'Misc Sugar Products',':-)',':->',':-<',
  313.                         ':-(','Tom Jones Rulz (joke)','Beverly Hills 90210',
  314.                         'Melrose Place','The Simpsons','I\am a tea pot',
  315.                         'SPAWN','Homer','Bart!','Maggie','Lisa','Marge',
  316.                         'Mr Burns','Smithers','Ned Flanders'    ]
  317.  
  318.     /*    A LIST of LISTs containing LISTs of spacial coordinates.  These
  319.         should only be CHARs but then they wouldn't be E Lists anymore. :-(
  320.  
  321.         format:        [    [    [1,2,3],    coords
  322.                             [4,5,6]        coords    ]    object    ]    shapelist
  323.     */
  324.  
  325.     shapelist:=[[     [    255,    0,    128,    0,    0,    255,    79,    243,    128,
  326.                         255,    0,    128,    79,    -243,    128,    0,    0,    255 ],
  327.                     [    -207,    -150,    128,    0,    0,    255,    -207,    150,    128,
  328.                         -207,    -150,    128,    79,    -243,    128 ],
  329.                     [    79,    243,    128,    -207,    150,    128 ],
  330.                     [    207,    150,    -128,    0,    0,    -255,    -79,    243,    -128,
  331.                         207,    150,    -128,    207,    -150,    -128,    0,    0,    -255 ],
  332.                     [    -79,    -243,    -128,    0,    0,    -255,    -255,    0,    -128,
  333.                         -79,    -243,    -128,    207,    -150,    -128 ],
  334.                     [    -79,    243,    -128,    -255,    0,    -128,    -207,    150,    128,
  335.                         -79,    243,    -128,    79,    243,    128,    207,    150,    -128,
  336.                         255,    0,    128,    207,    -150,    -128,    79,    -243,    128,
  337.                         -79,    -243,    -128,    -207,    -150,    128,    -255,    0,    -128 ] ],
  338.  
  339.                 [    [R,R,R,R,R,-R,R,-R,-R,R,-R,R,R,R,R,R,-R,R,-R,-R,R,-R,R,R,R,R,R],
  340.                     [-R,-R,-R,-R,-R,R,-R,R,R,-R,R,-R,-R,-R,-R,-R,R,-R,R,R,-R,R,-R,-R,-R,-R,-R]    ],
  341.  
  342.                 [    [0,100,0, 100,-100,-100, 100,-100,100, 0,100,0, -100,-100,100, 100,-100,100],
  343.                     [0,100,0, -100,-100,100, -100,-100,-100, 0,100,0, 100,-100,-100, -100,-100,-100]]]
  344.  
  345.     shapenames:=['Icosahedron','Wouter\as Cube','A pointy thing.']
  346.  
  347.     /* I'v hiden the colours in the first byte of shapesizes as the values
  348.     are so big, a few extra won't hurt - pritty silly, i know.  In general,
  349.     not good practice - but ain't it fun!  */
  350.  
  351.     shapesizes:=[1800 OR WHT,1400 OR BLU,1200 OR GRY]
  352.  
  353.     /* All memtypes we must check - see:  OBJECT memblock (up there ^^^) */
  354.  
  355.     memlist:=[    [    MEMF_CHIP,'CHIP',LEFT, NIL,NIL,NIL    ]:memblock,
  356.                 [    MEMF_FAST,'FAST',RIGHT,NIL,NIL,NIL    ]:memblock ]
  357.  
  358.     perform([    `storetotal(available(MEMF_TOTAL OR mem.type)),
  359.                 `StringF(gstr,'\s',
  360.                     mem.text) BUT autotext(mem.position,BOTTOM1,gstr),
  361.                 `StringF(gstr,'\d K',
  362.                     mem.total) BUT autotext(mem.position,BOTTOM2,gstr),
  363.                 `level()    ])
  364.  
  365.     autotext(CENTRE,TOP1,'· MEMORY AVAILABLE ·')
  366.     autotext(CENTRE,BOTTOM2,'· MEMORY POOL TOTAL ·')
  367.  
  368.     setmiddle3d(150,90)
  369.     origpri:=setpri(-1)
  370.     setshape()
  371.     LOOP
  372.         IF images
  373.             /*  only redraw display if available memory has changed since last time */
  374.  
  375.             perform([    `storeavail(available(mem.type)),
  376.                         `IF mem.avail<>mem.lastavail THEN level() ELSE NIL    ])
  377.             drawshape(BLK)    /* Delete old image */
  378.             IF count++>MAXCOUNT
  379.                 count:=NIL
  380.                 IF currentshape++=(ListLen(shapelist)-1) THEN currentshape:=NIL
  381.                 setshape()
  382.             ENDIF
  383.  
  384.             /* rotate image */
  385.  
  386.             init3d(    phi        :=    IF phi>358 THEN 0 ELSE phi+2,
  387.                     theta    :=    IF theta>358 THEN 0 ELSE theta+3    )
  388.  
  389.             /*    Draw new image and extract the colour from
  390.                 shapesizes[currentshape] */
  391.  
  392.             drawshape(shapesizes[currentshape] AND $FF)
  393.         ENDIF
  394.             /*  We  check Gt_GetIMsg() every frame (or there abouts - if we
  395.                 can)  but  only update vectors every 'speed' (or there abouts -
  396.                 if we can :).  A timer would be more appropiate but that
  397.                 would take time (funny that) */
  398.         FOR frameloop:=1 TO speed
  399.             WaitTOF()
  400.             IF scrolldown=NIL
  401.                 /* scrolldown:=Rnd() # of frames to wait until next message */
  402.                 scrolldown:=Rnd(400)+100
  403.                 autotext(CENTRE,TOP2,messagelist[Rnd(ListLen(messagelist))])
  404.             ELSEIF scrolldown<11
  405.                 ScrollRaster(rast,0,-2,65,26,235,36)
  406.             ENDIF
  407.             scrolldown--    /* decrement scrolldown counter */
  408.             WHILE imes:=Gt_GetIMsg(wnd.userport)
  409.                 imclass:=imes.class
  410.                 code:=imes.code
  411.                 Gt_ReplyIMsg(imes)
  412.                 SELECT imclass
  413.                     CASE IDCMP_GADGETUP
  414.                         iaddress:=imes.iaddress
  415.                         Eval(iaddress.userdata)
  416.                     CASE IDCMP_CLOSEWINDOW
  417.                         autotext(CENTRE,TOP2,'BYE!   BYE!')
  418.                         /* Spilt the window down the middle! */
  419.                         FOR x:=1 TO 75
  420.                             WaitTOF()
  421.                             ScrollRaster(rast,2,0,0,0,150,195)
  422.                             ScrollRaster(rast,-2,0,150,0,300,195)
  423.                         ENDFOR
  424.                         setpri(origpri)
  425.                         Raise(NIL)
  426.                 ENDSELECT
  427.             ENDWHILE
  428.         ENDFOR
  429.     ENDLOOP
  430. EXCEPT
  431.     /* The advantages of exceptions are that they have stopped my IF ELSE
  432.         ENDIF nests flying of into buggery.  Thankyou Wouter!  */
  433.  
  434.     IF scr THEN UnlockPubScreen(NIL,NIL)
  435.     IF wnd THEN CloseWindow(wnd)
  436.     IF context THEN FreeGadgets(context)
  437.     IF visual THEN FreeVisualInfo(visual)
  438.     IF gadtoolsbase THEN CloseLibrary(gadtoolsbase)
  439.  
  440.     /* All the horrible things that could have gone wrong. */
  441.  
  442.     IF exception
  443.         WriteF('COLD COFFEE ALERT: Failure occured with no \s\n\b\n\b',
  444.             ListItem([    NIL,'Memory',{txt_gadtools},'Kick 2.0',
  445.                         'Screen Lock','Visual Info','Window',
  446.                         'Gadgets'],exception) )
  447.     ENDIF
  448. ENDPROC
  449.  
  450. /*    storetotal() and storeavail() where nessisary is E 2.1b does not allow..
  451.         `mem.avail:=available(mem.type)
  452.     ..which would have been alot more fun. */
  453.  
  454. PROC storetotal(x)
  455.     mem.total:=x
  456. ENDPROC
  457.  
  458. PROC storeavail(x)
  459.     mem.avail:=x
  460. ENDPROC
  461.  
  462. /*  Note  the double nested ForAll() performs all quoted expressions in the
  463.     list for all in 'memlist'.  */
  464.  
  465. PROC perform(list)
  466.     DEF exp
  467. ENDPROC ForAll({exp},list,`ForAll({mem},memlist,exp))
  468.  
  469. PROC level()
  470.     DEF offset,percent
  471.  
  472.     /* I doubt if this is very acurate - maths is not my forte */
  473.  
  474.     percent:=(mem.avail/(IF (x:=mem.total/100) THEN x ELSE 1))
  475.     offset:=mem.position
  476.     Box(offset,40,offset+41,140-percent,BLK)    /* Top bit */
  477.     Box(offset,140-percent,offset+41,140,BLU)    /* Bottom bit */
  478.     mem.lastavail:=mem.avail
  479.     StringF(gstr,'\d K',mem.avail) BUT autotext(mem.position,TOP1,gstr)
  480.     StringF(gstr,'\d %',percent) BUT autotext(mem.position,TOP2,gstr)
  481. ENDPROC
  482.  
  483. PROC setshape()
  484.     setpers3d(shapesizes[currentshape],300)
  485.     autotext(CENTRE,BOTTOM1,shapenames[currentshape])
  486. ENDPROC
  487.  
  488. /* autotext() displays all text detecting position and justifing. */
  489.  
  490. PROC autotext(x,y,string)
  491.     SELECT x
  492.         CASE LEFT
  493.             rast.cp_x:=14
  494.         CASE RIGHT
  495.             rast.cp_x:=284-tlen(string)
  496.         CASE CENTRE
  497.             Box(65,y-7,235,y+1,GRY)
  498.             rast.cp_x:=150-(tlen(string)/2)
  499.         DEFAULT
  500.             rast.cp_x:=x
  501.     ENDSELECT
  502.     rast.cp_y:=y
  503.     Colour(BLK,GRY)
  504. ENDPROC Text(rast,string,StrLen(string))
  505.  
  506. PROC tlen(string)
  507. ENDPROC TextLength(rast,string,StrLen(string))
  508.  
  509. PROC available(memf)
  510. ENDPROC AvailMem(memf OR MEMF_PUBLIC)/1024
  511.  
  512. PROC setpri(pri)
  513. ENDPROC SetTaskPri(thistask,pri)
  514.  
  515. PROC options()
  516.     DEF result
  517.  
  518.     /* We create the options accordingly */
  519.  
  520.     StringF(gstr,'\s Images|Rotate \s|Thankyou',
  521.         IF images THEN 'Stop' ELSE 'Start',
  522.         IF speed=SLOW THEN 'Fast' ELSE 'Slow')
  523.     result:=EasyRequestArgs(0,[20,0,0,{txt_about},gstr],0,NIL)
  524.     SELECT result
  525.         CASE 1
  526.             images:=IF images THEN FALSE ELSE TRUE
  527.         CASE 2
  528.             speed:=IF speed=SLOW THEN FAST ELSE SLOW
  529.     ENDSELECT
  530. ENDPROC
  531.  
  532. /* I had a spare button and decided to do something useless with it.  */
  533.  
  534. PROC jumpabout()
  535.     FOR x:=1 TO 5+Rnd(10) DO MoveWindow(wnd,100-Rnd(200),50-Rnd(100))
  536.     autotext(CENTRE,TOP2,'Arrrrr! This is fun!')
  537. ENDPROC
  538.  
  539. PROC drawshape(col)
  540.   DEF polygon
  541.  
  542.   ForAll({polygon},shapelist[currentshape],`polygon3d(polygon,col))
  543. ENDPROC
  544.  
  545. /* Since we use this string twice, why not reference it through {}
  546.  
  547.     Hurry up Wouter and make:    CONST MYSTRING='E is cool'
  548.  
  549. */
  550.  
  551. txt_gadtools:
  552.  
  553. CHAR 'gadtools.library',0
  554.  
  555. txt_about:
  556.  
  557. CHAR    '           The Fuel Guage\n\n',
  558.         '© COPYRIGHT 1994 Christian Catchpole\n\n',
  559.         '         COLD COFFEE DESIGN\n',
  560.         'MADE IN AUSTRALIA - CONTAINS CAFFEINE\n\n',
  561.         'Written in Wouter\as E2.1b using some\n',
  562.         'routines from \avec.e\a. E users and\n',
  563.         'all others please write (100%% Legal :).\n\n',
  564.         'Snail Mail:  CHRISTIAN CATCHPOLE,\n',
  565.         '             P.O. BOX 388,\n',
  566.         '             CHERMSIDE 4032,\n',
  567.         '             AUSTRALIA\n',0
  568.  
  569. /********* This is Wouter's from here down ********/
  570.  
  571. PROC polygon3d(list:PTR TO LONG,col)
  572.   DEF n,i,sx,sy,ox,oy,f=FALSE
  573.   n:=ListLen(list)/3
  574.   FOR i:=1 TO n
  575.     vec3d(list[]++,list[]++,list[]++,{sx},{sy})
  576.     IF f THEN Line(ox,oy,sx,sy,col) ELSE f:=TRUE
  577.     ox:=sx; oy:=sy;
  578.   ENDFOR
  579. ENDPROC
  580.  
  581. PROC init3d(phi,theta)
  582.     MOVE.L    sintab,A0        /* uses A0,A1,D0 */
  583.     LEA    c1(PC),A1
  584.     MOVE.L    phi,D0
  585.     LSL.W    #1,D0
  586.     MOVE.W    0(A0,D0.W),6(A1)
  587.     ADD.W    #180,D0
  588.     MOVE.W    0(A0,D0.W),2(A1)
  589.     MOVE.L    theta,D0
  590.     LSL.W    #1,D0
  591.     MOVE.W    0(A0,D0.W),4(A1)
  592.     ADD.W    #180,D0
  593.     MOVE.W    0(A0,D0.W),(A1)
  594. ENDPROC
  595.  
  596. PROC setpers3d(irho,id)        /* for average size rho:d = 5:2 */
  597.     LEA    rho(PC),A0
  598.     MOVE.W    irho.W,(A0)
  599.     MOVE.W    id.W,2(A0)
  600. ENDPROC
  601.  
  602. PROC setmiddle3d(x,y)
  603.     LEA    midx(PC),A0
  604.     MOVE.W    x.W,(A0)
  605.     MOVE.W    y.W,2(A0)
  606. ENDPROC
  607.  
  608. c1:    INT    $00c2
  609. c2:    INT    $0045
  610. s1:    INT    $00a3
  611. s2:    INT    $00f5
  612. rho:    INT    2000
  613. d:    INT    900
  614. midx:    INT    160
  615. midy:    INT    128
  616.  
  617. PROC vec3d(x,y,z,sx,sy)
  618.     MOVE.L    x,D0
  619.     MOVE.L    y,D1
  620.     MOVE.L    z,D2
  621.     MOVE.L    A4,-(A7)
  622.     MOVE.W    c1(PC),D3
  623.     MOVE.W    c2(PC),D4
  624.     MOVE.W    s1(PC),D5
  625.     MOVE.W    s2(PC),D6
  626.     MOVE    D0,D7            /* EXPECTS X,Y,Z IN D0-D2 */
  627.     MULS    D5,D7            /* TRASHES ALL REGS BUT A5-A7 */
  628.     ASR.L    #8,D7
  629.     MOVE    D7,A0            /* TEMP1 = X*S1 */
  630.     MOVE    D1,D7
  631.     MULS    D3,D7
  632.     ASR.L    #8,D7
  633.     SUB    A0,D7
  634.     MOVE    D7,A2            /* XE = Y*C1-TEMP1 */
  635.     MOVE    D1,D7
  636.     MULS    D5,D7
  637.     ASR.L    #8,D7
  638.     MULS    D4,D7
  639.     ASR.L    #8,D7
  640.     MOVE    D7,A0            /* TEMP1 = Y*S1*C2 */
  641.     MOVE    D0,D7
  642.     MULS    D3,D7
  643.     ASR.L    #8,D7
  644.     MULS    D4,D7
  645.     ASR.L    #8,D7
  646.     MOVE    D7,A1            /* TEMP2 = X*C1*C2 */
  647.     MOVE    D2,D7
  648.     MULS    D6,D7
  649.     ASR.L    #8,D7
  650.     SUB    A0,D7
  651.     SUB    A1,D7
  652.     MOVE    D7,A3            /* YE = Z*S2-TEMP1-TEMP2 */
  653.     MULS    D6,D0
  654.     ASR.L    #8,D0
  655.     MULS    D3,D0
  656.     ASR.L    #8,D0
  657.     MOVE    D0,A0            /* TEMP1 = X*S2*C1 */
  658.     MULS    D6,D1
  659.     ASR.L    #8,D1
  660.     MULS    D5,D1
  661.     ASR.L    #8,D1
  662.     MOVE    D1,A1            /* TEMP2 = Y*S2*S1 */
  663.     NEG    D2
  664.     MULS    D4,D2
  665.     ASR.L    #8,D2
  666.     ADD    rho(PC),D2
  667.     SUB    A0,D2
  668.     SUB    A1,D2            /* ZE(D2) = -Z*C2+RHO-TEMP1-TEMP2 */
  669.     MOVE    A2,D3
  670.     MOVE    A3,D4
  671.     MOVE    d(PC),D0
  672.     MOVE    D0,D1
  673.     MULS    D3,D0
  674.     DIVS    D2,D0
  675.     ADD    midx(PC),D0        /* SX(D0) = D*XE/ZE+160 */
  676.     NEG    D1
  677.     MULS    D4,D1
  678.     DIVS    D2,D1
  679.     ADD    midy(PC),D1        /* SY(D1) = -D*YE/ZE+128 */
  680.     MOVE.L    (A7)+,A4
  681.     MOVE.L    sx,A0
  682.     EXT.L    D0
  683.     MOVE.L    D0,(A0)
  684.     MOVE.L    sy,A0
  685.     EXT.L    D1
  686.     MOVE.L    D1,(A0)
  687. ENDPROC
  688.